
let mapContext;
let originPosition;
const netImage = 'https://image.baidu.com/search/down?&tn=download&word=download&ie=utf8&fr=home&url=http%3A%2F%2Fgips3.baidu.com%2Fit%2Fu%3D3886271102%2C3123389489%26fm%3D3028%26app%3D3028%26f%3DJPEG%26fmt%3Dauto%3Fw%3D1280%26h%3D960&thumbUrl=http%3A%2F%2Fgips3.baidu.com%2Fit%2Fu%3D3886271102%2C3123389489%26fm%3D3028%26app%3D3028%26f%3DJPEG%26fmt%3Dauto%3Fw%3D1280%26h%3D960&iswise=1';
Page({
    data: {
        width: 300,
        height: 300,
        renderWidth: 300,
        renderHeight: 300,
    },
    onReady() {
        this.testLocation();
        // const info = wx.getSystemInfoSync();
        // const width = info.windowWidth;
        // const height = info.windowHeight;
        // const dpi = info.pixelRatio;
        // this.setData({
        //   width, height,
        //   renderWidth: width * dpi,
        //   renderHeight: height * dpi
        // });
    },
    onLoad() {
      const info = wx.getSystemInfoSync();
      const width = info.windowWidth;
      const height = info.windowHeight;
      const dpi = info.pixelRatio;
      this.setData({
        width, height,
        renderWidth: width * dpi,
        renderHeight: height * dpi
      });

    },
    methods: {

    },
    testLocation() {
        mapContext = wx.createMapContext("mainMap", this);
        mapContext.enableZoom = false;

        async function addGroundOverlay(r) {
            console.log('--------------addGroundOverlay---------------', originPosition);

            const northeast = {
                latitude: originPosition.latitude + 0.1,//0.00000000001
                longitude: originPosition.longitude + 0.1
            };
            const southwest = {
                latitude: originPosition.latitude - 0.1,
                longitude: originPosition.longitude - 0.1
            };;
            const bounds = {
                northeast,
                southwest
            };
            console.log('bounds:', bounds);

            mapContext.addGroundOverlay({
                id: 1111111,
                src:netImage,
                // src: '/assets/img/11.jpeg',
                bounds: bounds,
                visible: true,
                zIndex: 10,
                opacity: 0.8,
                complete: (res) => {
                    console.log('addGroundOverlay complete:', res);
                    return 'complete';
                },
                fail: (res) => {
                    console.log('addGroundOverlay fail:', res);
                    return 'failed';
                },
                success: (res) => {
                    console.log('addGroundOverlay success:', res);
                    return 'success;'
                }
            })
        }
        function startMove() {
            console.log('--------------------start move------------------------');
            return;
            let lati = originPosition.latitude;
            let longitude = originPosition.longitude;
            setInterval(() => {
                mapContext.moveToLocation({
                    latitude: lati += 0.00000000000001,
                    longitude: longitude += 0.00000000000001,
                    complete: (res) => {
                        console.log('move to location complete:', res, lati, longitude)
                    },
                    fail: (res) => {
                        console.log('move to location fail:', res)
                    }
                })
            }, 3000);
        }
        mapContext.getCenterLocation().then(r => {
            originPosition = r;
            console.log('getCenterLocation:', r);
            addGroundOverlay().then(res => {
                // startMove(r).then();
            })

        });

    }
})
